package data;

public class demo03 {
    public static void main(String[] args) {
        /*数据类型的字节数从小到大排列
        * byte/boolean 、 short/char 、 int/float 、 long/double*/
        int i = 128;
        double b = i;
        System.out.println(i);
        System.out.println(b);
//      字符与整数运算
        char world = 'A';
        int num = world;
        System.out.println(world);  //输出为A
        System.out.println(num);  //输出为65 将字符转换为数值

//        强制类型转换
        int m = 20;
        byte n = (byte) m;  //快捷键：alt+enter选第一个
        System.out.println(n);//输出为20

        int k = 1500;
        byte k2 = (byte) k;
        System.out.println(k2);//输出为-36，有溢出

        double d = 99.5;
        int d1 = (int) d;
        System.out.println(d1);  //输出为99，double转为int,小数部分被丢掉


//        表达式自动转换由最高类型决定
        byte a = 10;
        short s = 20;
        long c = 30L;
        long rs = a + s + c;
        System.out.println(rs);  //c是最高变量
        double rs2 = a + s + 1.2;  //1.2是double类型，是最高变量
        System.out.println(rs2);
        int rs3 = a + s;  //byte、short、char这三种类型是直接转换成int类型参与运算的
        System.out.println(rs3);



        int money = 1_000_000_000;  //JDK7特性，数字之间可以用下划线分割，不影响输出结果
        int year = 20;
        int total1 = money * year;   //-1474836480 数值太大溢出
        long total2 = money * year;  //-1474836480 默认是int，转换的是溢出后的结果
        long total3 = (long) money * year;  //20000000000 先把一个数转换为long
        long total4 = money * (long) year;  //20000000000
        long total5 = (long) money * (long) year;  //20000000000
        System.out.println(total1);
        System.out.println(total2);
        System.out.println(total3);
        System.out.println(total4);
        System.out.println(total5);

    }
}